{include file="public/header"}
<body>
<div id="app" v-cloak>
    <div class="ht-main">
        <div class="ht-search">
            <el-form :inline="true" size="small">
                <el-form-item label="昵称">
                    <el-input placeholder="昵称" v-model="searchKey.tel"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="success" icon="el-icon-search" @click="search">搜索</el-button>
                    <el-button type="" icon="el-icon-refresh" @click="reset">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="ht-tool">
            <div class="ht-tool-left">
                <!-- <el-button type="success" size="mini" icon="el-icon-plus" @click="doAdd">添加</el-button> -->
                <el-button type="primary" :disabled="tableSelect.length !== 1" size="mini" icon="el-icon-edit"
                           @click="edit(tableSelect[0])">编辑
                </el-button>
                <el-button type="danger" :disabled="!tableSelect.length" size="mini" icon="el-icon-delete"
                           @click="batchDel('/admin/user/del')">删除
                </el-button>
            </div>
            <div class="ht-tool-right">
            </div>
        </div>
        <div class="ht-main-body">
            <el-table :data="tableData" border header-row-class-name="ht-table-header"
                      ref="dataTable" @selection-change="handleSelectChange"
                      row-key="title"
                      :tree-props="{children:'children'}"
            >
                <el-table-column align="center" type="selection" width="39"></el-table-column>
                <el-table-column align="center" prop="id" label="ID" type="" width="80px"></el-table-column>
                <el-table-column align="center" prop="avatar" label="头像">
                    <template slot-scope="scope">
                        <img :src="scope.row.avatar" style="max-width: 50px;" @click="showImg(scope.row.avatar)">
                    </template>
                </el-table-column>
                <el-table-column align="center" prop="nick" label="昵称"></el-table-column>
                <el-table-column align="center" prop="xianqi" label="仙气"></el-table-column>
                <el-table-column align="center" prop="store_num" label="仓库"></el-table-column>
                <el-table-column align="center" prop="qwen_token" label="token"></el-table-column>
                <el-table-column align="center" prop="status" label="状态">
                    <template slot-scope="scope">
                        <el-switch
                                @change="setStatus(scope.row)"
                                v-model="scope.row.status"
                                active-color="#13ce66"
                                inactive-color="#ff4949" :inactive-value="-1"
                                :active-value="1">
                        </el-switch>
                    </template>
                </el-table-column>
                <el-table-column align="center" prop="create_time" width="180" label="注册时间"></el-table-column>
                <el-table-column align="center" label="操作" width="180">
                    <template slot-scope="scope">
                        <el-button @click="edit(scope.row)" size="mini" type="primary" icon="el-icon-edit"></el-button>
                        <el-button @click="del(scope.row)" size="mini" type="danger" icon="el-icon-delete"></el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="ht-main-page">
                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="page"
                        :page-sizes="[1,10, 200, 300, 400]"
                        :page-size="limit"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total">
                </el-pagination>
            </div>
            <el-drawer
                    :visible.sync="is_edit"
                    size="80%"
                    :with-header="false"
                    custom-class="ht-drawer-bg"
            >
                <div class="ht-drawer-main">
                    <el-page-header @back="goBack" title="Esc返回" :content="content"></el-page-header>
                    <div class="ht-form">
                        <el-form :model="editData" label-width="120px" size="small">
                            <el-form-item label="仓库">
                                <el-input type="text" autocomplete="off" placeholder="仓库" v-model="editData.store_num"></el-input>
                            </el-form-item>
                            <el-form-item label="仙气">
                                <el-input type="text" autocomplete="off" placeholder="仙气" v-model="editData.xianqi"></el-input>
                            </el-form-item>
                            <el-form-item>
                                <el-button @click="goBack">取消</el-button>
                                <el-button type="primary" @click="onSubmit" :loading="is_load">提交</el-button>
                            </el-form-item>
                        </el-form>
                    </div>
                </div>
            </el-drawer>
        </div>
    </div>
</div>
{include file="public/common"}
<script src="/static/elementUi/component/form_image.js"></script>
<script>
    let vs ;
    let del_url = "{:url('user/del')}";
    let add_url = "{:url('user/add')}";
    let index_url = "{:url('user/index')}";
    var vm = new Vue({
        el: "#app",
        data: function () {
            return {
                is_load:false,
                inputValue: '',
                inputVisible: false,
                showDialog: false,
                activeTab: 'first',
                tableData: [],
                cinema_list:[],
                is_edit: false,
                editData: {},
                editDataTemp: {},
                content: '编辑',
                total: 0,
                page: 1,
                limit: 10,
                fileManage:false,
                options:[],
                contacts:[{name:'',tel:''}]
            }
        },
        created: function () {
            vs = this;
            vs.getData()
        },
        methods: {
            changeCourier(row) {
                Api.request("{:url('user/changeCourier')}",{id:row.id}).then(res=>{
                    vs.getData();
                })
            },
            getIndex() {
                vs.getData()
            },
            getCategory() {
                $.post("{:url('category/all')}",function (res) {
                    if (res.code == 1) {
                        vs.categoryList = res.data
                    }
                })
            },
            setStatus(row) {
                Api.request("{:url('user/setStatus')}",{id:row.id})
            },
            onSubmit() {
                var that = this
                vs.is_load = true
                Api.request(add_url,vs.editData).then(res=>{
                    that.showSuccessMsgCall(function () {
                        that.is_edit = false;
                        that.editData = {};
                        that.getData()
                    })
                }).finally(()=>{
                    vs.is_load = false
                })
            },
            getData: function () {
                var that = this
                that.searchType = {
                    title: 'like',
                    flag: 'like'
                };
                $.post(index_url, {
                    limit: that.limit,
                    page: that.page,
                    search_key: that.searchKey,
                    search_type: that.searchType
                }, function (res) {
                    if (res.code == 1) {
                        that.tableData = res.data.data
                        that.total = res.data.total
                    } else {
                        that.showErrorMsg(res.msg)
                    }
                })
            },
            doAdd: function () {
                this.is_edit = true
                this.content = '添加'
                this.editData = {}
            },
            edit: function (data) {
                this.is_edit = true
                this.content = '编辑'
                this.editData = JSON.parse(JSON.stringify(data))
                console.log(data)
            },
            goBack: function () {
                this.is_edit = false
            },
            del: function (data) {
                var that = this
                that.$confirm('确定删除么?', '提示', {
                    type: 'warning',
                    lockScroll: false
                }).then(() => {
                    $.post(del_url, {id: data.id}, function (res) {
                        if (res.code == 1) {
                            that.showSuccessMsgCall(function () {
                                that.getData()
                            })
                        } else {
                            that.showErrorMsg(res.msg)
                        }
                    })
                })
            },
            handleSizeChange: function (e) {
                this.limit = e
            },
            handleCurrentChange: function (e) {
                this.page = e
            }
        },
        watch: {
            page(v) {
                this.getData()
            },
            limit() {
                this.getData()
            }
        }
    })
</script>
</body>
</html>
